import {
	TUILogin,
} from "@tencentcloud/tui-core"
import TencentCloudChat from '@tencentcloud/chat'
import {
	getImUserSigAPI
} from '@/api/chat.js'
export const chat2 = {
	chat: null,
	initialize: () => {
		return new Promise((resolve, reject) => {
			getImUserSigAPI().then((item) => {
				resolve(item.data)
			})
		});
	},
	chatTUILoginOut() {
		TUILogin.logout()
	},
	chatTUILogin(data) {
		return new Promise((resolve, reject) => {
			TUILogin.login({
				SDKAppID: data.sdkappid,
				userID: data.user_id + '',
				userSig: data.sign,
				useUploadPlugin: true, // If you need to send rich media messages, please set to true.
				framework: `vue3` // framework used vue2 / vue3
			}).then((res) => {
				resolve("ok")
			}).catch((err) => {
				console.error(err)
				reject()
			})

			console.log(TUILogin.getContext())
			this.chat = TUILogin.getContext().chat
			this.chat.on(TencentCloudChat.EVENT.KICKED_OUT, () => {
				uni.showToast({
					title: "账号在别处登录",
					icon: "none"
				})
				setTimeout(() => {
					uni.reLaunch({
						url: '/pages/login/index'
					})
				},500)
			})
		})


	}
}